package org.deltaset.meta.internal;

import org.deltaset.meta.ExecuteListener;
import org.deltaset.meta.MetaActionHandler;
import org.deltaset.meta.MetaEntry;
import org.deltaset.meta.TitleResolver;
import org.deltaset.meta.aware.ExecuteListenerProviderAware;
import org.deltaset.meta.aware.RepositoryProviderAware;
import org.deltaset.meta.aware.TitleResolverProviderAware;
import org.deltaset.meta.extension.ExecuteListenerProvider;
import org.deltaset.meta.extension.MetaHandlerProvider;
import org.deltaset.meta.extension.RepositoryProvider;
import org.deltaset.meta.extension.TitleResolverProvider;

/**
 *
 * @author dmakariev
 */
public final class DefaultMetaHandlerProvider implements MetaHandlerProvider, RepositoryProviderAware, TitleResolverProviderAware, ExecuteListenerProviderAware {

    private RepositoryProvider repositoryProvider;
    private TitleResolverProvider titleResolverProvider;
    private ExecuteListenerProvider executeListenerProvider;

//    @Override
//    public MetaHandler createMetaHandler(Class entityClass) {
//        final MetaClass metaClass = MetaClassFactory.forClass(entityClass, repositoryProvider);
//        final TitleResolver titleResolver = titleResolverProvider.createTitleResolver();
//        final ExecuteListener executeListener = executeListenerProvider.createExecutionListener();
//        final MetaActionHandlerImpl actionHandlerImpl = new MetaActionHandlerImpl(repositoryProvider, titleResolver, executeListener);
//        final MetaEntryImpl entryImpl = new MetaEntryImpl(metaClass);
//        return new MetaHandlerImpl(entryImpl, actionHandlerImpl);
//    }

    @Override
    public MetaActionHandler createMetaActionHandler() {
        final TitleResolver titleResolver = titleResolverProvider.createTitleResolver();
        final ExecuteListener executeListener = executeListenerProvider.createExecutionListener();
        final MetaActionHandlerImpl actionHandlerImpl = new MetaActionHandlerImpl(repositoryProvider, titleResolver, executeListener);
        return actionHandlerImpl;
    }

    @Override
    public MetaEntry createMetaEntry(Class entityClass) {
        final MetaClass metaClass = MetaClassFactory.forClass(entityClass, repositoryProvider);
        final MetaEntryImpl entryImpl = new MetaEntryImpl(metaClass);
        return entryImpl;
    }

    @Override
    public void setRepositoryProvider(RepositoryProvider repositoryProvider) {
        this.repositoryProvider = repositoryProvider;
    }

    @Override
    public void setTitleResolverProvider(TitleResolverProvider titleResolverProvider) {
        this.titleResolverProvider = titleResolverProvider;
    }

    @Override
    public void setExecuteListenerProvider(ExecuteListenerProvider executeListenerProvider) {
        this.executeListenerProvider = executeListenerProvider;
    }
}
